import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:jxchmz/%E4%BB%93%E7%AE%A1/%E5%BA%93%E5%AD%98%E6%9F%A5%E8%AF%A2/GoodsSearch.dart';
import 'package:jxchmz/%E4%BB%93%E7%AE%A1/%E5%BA%93%E5%AD%98%E8%B0%83%E6%8B%A8/GoodsTransferList.dart';
import 'package:jxchmz/%E4%BB%93%E7%AE%A1/%E7%89%A9%E8%B5%84%E5%85%A5%E5%BA%93/GoodsEntry.dart';
import 'package:jxchmz/%E4%BB%93%E7%AE%A1/%E7%89%A9%E8%B5%84%E5%85%A5%E5%BA%93/PrfOrderList.dart';
import 'package:jxchmz/%E4%BB%93%E7%AE%A1/%E7%89%A9%E8%B5%84%E5%87%BA%E5%BA%93/OutOrderList.dart';
import 'package:jxchmz/%E4%BB%93%E7%AE%A1/%E7%89%A9%E8%B5%84%E7%9B%98%E7%82%B9/GoodsInventoryList.dart';
import 'package:jxchmz/%E6%88%91%E7%9A%84/UserCenter.dart';
import 'package:jxchmz/%E8%AE%BE%E5%A4%87%E8%BF%9E%E6%8E%A5/DeviceConnect.dart';
import 'package:jxchmz/%E9%94%80%E5%94%AE/%E4%BC%9A%E5%91%98%E7%99%BB%E8%AE%B0/VipAdd.dart';
import 'package:jxchmz/%E9%94%80%E5%94%AE/%E9%94%80%E5%94%AE%E7%89%A9%E8%B5%84%E5%BD%95%E5%85%A5/GoodsLuRu.dart';
import 'package:jxchmz/%E9%94%80%E5%94%AE/%E9%94%80%E5%94%AE%E8%AE%B0%E5%BD%95/SalNotes.dart';
import 'package:jxchmz/API/%E5%BA%93%E5%AD%98%E7%AE%A1%E7%90%86/KuCunManager.dart';
import 'package:jxchmz/API/%E7%94%A8%E6%88%B7%E4%BF%A1%E6%81%AF/UserMessage.dart';
import 'package:jxchmz/API/%E9%94%80%E5%94%AE%E7%AE%A1%E7%90%86/SaleManage.dart';
import 'package:jxchmz/Getx%E5%B7%A5%E5%85%B7/GetxTools.dart';
import 'package:jxchmz/Getx%E5%B7%A5%E5%85%B7/KSProgressDialog.dart';

class Home extends StatefulWidget {
  @override
  _HomeState createState() => new _HomeState();
}

class _HomeState extends State<Home> with AutomaticKeepAliveClientMixin {
  @override
  bool get wantKeepAlive => true; //要点2
  //本地缓存
  GetStorage getStorage = new GetStorage();

  //仓管界面
  List CangGuanHomeList = [
    {"Name": "Deviceconnection".tr, "ImgUrl": "bangding", "id": 0},
    {"Name": "Suppliesareputintostorage".tr, "ImgUrl": "wuziruku", "id": 1},
    {"Name": "Suppliesoutofthewarehouse".tr, "ImgUrl": "yiku", "id": 2},
    {"Name": "Materialinventory".tr, "ImgUrl": "pandian", "id": 3},
    {"Name": "Inventoryinquiry".tr, "ImgUrl": "kucunchaxunsvg", "id": 4},
    {"Name": "Inventoryallocation".tr, "ImgUrl": "tiaobo", "id": 5},
  ];

  //销售界面
  List XiaoShouHomeList = [
    // {"Name": "设备连接", "ImgUrl": "bangding", "id": 0},
    // {"Name": "销售录入", "ImgUrl": "jihaoluru", "id": 7},
    {"Name": "MembershipRegistration".tr, "ImgUrl": "huiyuan2", "id": 8},
    {"Name": "Salesrecords".tr, "ImgUrl": "xiaoshoujilu", "id": 9},
  ];

  //店长界面
  List DianZhangHomeList = [
    {"Name": "Deviceconnection".tr, "ImgUrl": "bangding", "id": 0},
    {"Name": "Suppliesareputintostorage".tr, "ImgUrl": "wuziruku", "id": 1},
    {"Name": "Suppliesoutofthewarehouse".tr, "ImgUrl": "yiku", "id": 2},
    {"Name": "Materialinventory".tr, "ImgUrl": "pandian", "id": 3},
    {"Name": "Inventoryinquiry".tr, "ImgUrl": "kucunchaxunsvg", "id": 4},
    {"Name": "Inventoryallocation".tr, "ImgUrl": "tiaobo", "id": 5},
    // {"Name": "销售录入", "ImgUrl": "jihaoluru", "id": 7},
    {"Name": "MembershipRegistration".tr, "ImgUrl": "huiyuan2", "id": 8},
    {"Name": "Salesrecords".tr, "ImgUrl": "xiaoshoujilu", "id": 9},
  ];

  //权限标识 0销售  1仓管  2店长
  var permissions = 1;
  var lastPopTime;
  //今日订单
  int listDayNum = 0;
  //今日收入
  double listDayCount = 0.0;
  //总订单
  int listAllNum = 0;
  //进入入库
  int listDay = 0;
  //今日出库
  int listDayOut = 0;
  //总库存
  int listAll = 0;

  //权限
  var roleName;



//页面加载完成时
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    //获取用户信息
    Future.delayed(Duration.zero, () {
      GetUserMessage();
    });
  }

  ///页面卸载
  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
  }

  // TODO: add state variables and methods
  @override
  Widget build(BuildContext context) {
    super.build(context); //要点3
    // TODO: add widget build method
    SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.top,SystemUiOverlay.bottom]);
    // //设置状态栏颜色
    // SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
    //
    //
    // ));
    return Scaffold(
      backgroundColor: Color(0xfff3f3f3),
      appBar: AppBar(
        backgroundColor: Color(0xff95c1fe),
        elevation: 0,
        toolbarHeight: 0,
          systemOverlayStyle: SystemUiOverlayStyle(
            // statusBarColor: R.color.WHITE,
            statusBarColor: Color(0xff95c1fe), //状态栏背景颜色
            statusBarIconBrightness: Brightness.dark // dark:一般显示黑色   light：一般显示白色
          ),
      ),
      body: RefreshIndicator(
        onRefresh: GetUserMessage,
        child: WillPopScope(

          onWillPop: () async {
            // 点击返回键的操作
            if (lastPopTime == null ||
                DateTime.now().difference(lastPopTime!) > Duration(seconds: 1)) {
              lastPopTime = DateTime.now();
              GetxTools().WaringToast("PressExitagain".tr);
              return Future.value(false);
            } else {
              lastPopTime = DateTime.now();
              // 退出app
              return Future.value(true);
            }
          },
          child: Container(
            child: Column(
              children: [

                Stack(
                  alignment: Alignment.bottomCenter,
                  clipBehavior: Clip.none,
                  children: [
                    //头部
                    Container(
                      height: 140,
                      decoration: BoxDecoration(
                        // color: Color(0xffEEF4F4),
                        //   borderRadius: BorderRadius.only(
                        //     bottomLeft: Radius.circular(50),
                        //     bottomRight: Radius.circular(50),
                        //   ),
                          gradient: LinearGradient(
                              begin: Alignment.topCenter,//渐变开始于上面的中间开始
                              end: Alignment.bottomCenter,//渐变结束于下面的中间
                              colors: [Color(0xff95c1fe), Color(0xff91c4fd),Color(0xff8dcbfe),Color(0xff87d0fb),Color(0xff85d3ff)])
                      ),

                      child: Container(
                        padding: EdgeInsets.all(20),
                        child: Row(

                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Container(
                              child: Column(
                                mainAxisAlignment: MainAxisAlignment.center,
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Text(
                                    "Welcometouse".tr+"Invoicingandinventorymanagement".tr,
                                    style: TextStyle(fontWeight: FontWeight.w700, fontSize: 17,color: Colors.white),
                                  ),
                                  Text("Currentrolepermissions".tr+":$roleName",style: TextStyle(color: Colors.white),)
                                  // Text("Currentrolepermissions".tr+":${permissions == 0 ? 'sale'.tr : permissions == 1 ? 'Warehousemanagement'.tr : 'Storemanager'.tr}",style: TextStyle(color: Colors.white),)
                                ],
                              ),
                            ),
                            //头像
                            Container(
                              width: 70,
                              height: 70,
                              padding: EdgeInsets.all(3),
                              decoration: BoxDecoration(shape: BoxShape.circle, color: Colors.white),
                              child: Container(
                                decoration: BoxDecoration(
                                    shape: BoxShape.circle, image: DecorationImage(image: AssetImage('Image/header.jpg'), fit: BoxFit.cover)),
                              ),
                            )
                          ],
                        ),
                      ),
                    ),
                    Positioned(
                      top:100,
                      child: //信息统计 销售
                    permissions == 0
                        ? Container(
                      margin: EdgeInsets.only(top: 15),
                      width: MediaQuery.of(context).size.width - 50,
                      padding: EdgeInsets.all(5),
                      decoration: BoxDecoration(
                        color: Color(0xffffffff),
                        borderRadius: BorderRadius.circular(10.0),
                        boxShadow: [
                          BoxShadow(
                              color: Colors.black12,
                              offset: Offset(0.0, 0.0), //阴影x轴偏移量
                              blurRadius: 5, //阴影模糊程度
                              spreadRadius: 1 //阴影扩散程度
                          )],
                      ),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Container(
                            padding: EdgeInsets.only(left: 5,right: 5,top: 15,bottom: 10),
                            child: Container(
                              // padding: EdgeInsets.only(right: 15),
                              // decoration: BoxDecoration(
                              //     border: Border(right: BorderSide(color: Colors.white,width: 0.5,style: BorderStyle.solid))
                              // ),
                              child: Column(
                                children: [Text("OrderToday".tr, style: TextStyle(color: Colors.black54)), Text("$listDayNum", style: TextStyle(color: Colors.black54))],
                              ),
                            ),
                          ),
                          Container(
                            padding: EdgeInsets.only(left: 5,right: 5,top: 15,bottom: 10),
                            child: Container(
                              child: Column(
                                children: [
                                  Text("Totalorders".tr, style: TextStyle(color: Colors.black54,  fontSize: 20)),
                                  Container(
                                    height: 8,
                                  ),
                                  Text("$listAllNum", style: TextStyle(color: Colors.black54, fontSize: 20))
                                ],
                              ),
                            ),
                          ),
                          Container(
                            padding: EdgeInsets.only(left: 5,right: 5,top: 15,bottom: 10),
                            child: Container(
                              child: Column(
                                children: [
                                  Text(
                                    "Todaysincome".tr,
                                    style: TextStyle(color: Colors.black54),
                                  ),
                                  Container(
                                    height: 8,
                                  ),
                                  Text("$listDayCount", style: TextStyle( color: Colors.black54))
                                ],
                              ),
                            ),
                          ),
                        ],
                      ),
                    )
                        : permissions == 1
                        ?
                    //信息统计 仓管、
                    Container(
                      margin: EdgeInsets.only(top: 15),
                      width: MediaQuery.of(context).size.width - 50,
                      padding: EdgeInsets.all(5),
                      decoration: BoxDecoration(
                        color: Color(0xffffffff),
                        borderRadius: BorderRadius.circular(10.0),
                        boxShadow: [
                          BoxShadow(
                              color: Colors.black12,
                              offset: Offset(0.0, 0.0), //阴影x轴偏移量
                              blurRadius: 5, //阴影模糊程度
                              spreadRadius: 1 //阴影扩散程度
                          )],
                      ),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Container(
                            padding: EdgeInsets.only(left: 5,right: 5,top: 15,bottom: 10),
                            child: Container(
                              // padding: EdgeInsets.only(right: 15),
                              // decoration: BoxDecoration(
                              //     border: Border(right: BorderSide(color: Colors.white,width: 0.5,style: BorderStyle.solid))
                              // ),
                              child: Column(
                                children: [
                                  Text("Inboundtoday".tr, style: TextStyle(color: Colors.black54)),
                                  Container(
                                    height: 8,
                                  ),
                                  Text("$listDay", style: TextStyle(color: Colors.black54))
                                ],
                              ),
                            ),
                          ),
                          Container(
                            padding: EdgeInsets.only(left: 5,right: 5,top: 15,bottom: 10),
                            child: Container(
                              child: Column(
                                children: [
                                  Text(
                                    "Totalinventory".tr,
                                    style: TextStyle(fontSize: 20, color: Colors.black54),
                                  ),
                                  Container(
                                    height: 8,
                                  ),
                                  Text("$listAll", style: TextStyle( fontSize: 20, color: Colors.black54))
                                ],
                              ),
                            ),
                          ),
                          Container(
                            padding: EdgeInsets.only(left: 5,right: 5,top: 15,bottom: 10),
                            child: Container(
                              child: Column(
                                children: [
                                  Text("Shippedtoday".tr, style: TextStyle(color: Colors.black54)),
                                  Container(
                                    height: 8,
                                  ),
                                  Text("$listDayOut", style: TextStyle(color: Colors.black54))
                                ],
                              ),
                            ),
                          )
                        ],
                      ),
                    )
                        :
                    //信息统计 店长
                    Column(
                      children: [
                        Container(
                          margin: EdgeInsets.only(top: 15),
                          width: MediaQuery.of(context).size.width - 50,
                          padding: EdgeInsets.all(5),
                          decoration: BoxDecoration(
                            color: Color(0xffffffff),
                            borderRadius: BorderRadius.circular(10.0),
                            boxShadow: [
                              BoxShadow(
                                  color: Colors.black12,
                                  offset: Offset(0.0, 0.0), //阴影x轴偏移量
                                  blurRadius: 5, //阴影模糊程度
                                  spreadRadius: 1 //阴影扩散程度
                              )],
                          ),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Container(
                                padding: EdgeInsets.only(left: 5,right: 5,top: 15,bottom: 10),
                                child: Container(
                                  // padding: EdgeInsets.only(right: 15),
                                  // decoration: BoxDecoration(
                                  //     border: Border(right: BorderSide(color: Colors.white,width: 0.5,style: BorderStyle.solid))
                                  // ),
                                  child: Column(
                                    children: [
                                      Text("Inboundtoday".tr, style: TextStyle(color: Colors.black54)),
                                      Container(
                                        height: 8,
                                      ),
                                      Text("$listDay", style: TextStyle(color: Colors.black54))
                                    ],
                                  ),
                                ),
                              ),
                              // Container(
                              //   padding: EdgeInsets.only(left: 5,right: 5,top: 15,bottom: 10),
                              //   child: Container(
                              //     child: Column(
                              //       children: [
                              //         Text(
                              //           "Totalinventory".tr,
                              //           style: TextStyle( fontSize: 20, color: Colors.black54),
                              //         ),
                              //         Container(
                              //           height: 8,
                              //         ),
                              //         Text("$listAll", style: TextStyle( fontSize: 20, color: Colors.black54))
                              //       ],
                              //     ),
                              //   ),
                              // ),
                              Container(
                                padding: EdgeInsets.only(left: 5,right: 5,top: 15,bottom: 10),
                                child: Container(
                                  child: Column(
                                    children: [
                                      Text("Shippedtoday".tr, style: TextStyle(color: Colors.black54)),
                                      Container(
                                        height: 8,
                                      ),
                                      Text("$listDayOut", style: TextStyle(color: Colors.black54))
                                    ],
                                  ),
                                ),
                              ),
                              Container(
                                padding: EdgeInsets.only(left: 5,right: 5,top: 15,bottom: 10),
                                child: Container(
                                  // padding: EdgeInsets.only(right: 15),
                                  // decoration: BoxDecoration(
                                  //     border: Border(right: BorderSide(color: Colors.white,width: 0.5,style: BorderStyle.solid))
                                  // ),
                                  child: Column(
                                    children: [
                                      Text("OrderToday".tr, style: TextStyle(color: Colors.black54)),
                                      Container(
                                        height: 8,
                                      ),
                                      Text("$listDayNum", style: TextStyle(color: Colors.black54))
                                    ],
                                  ),
                                ),
                              ),
                              // Container(
                              //   padding: EdgeInsets.only(left: 5,right: 5,top: 15,bottom: 10),
                              //   child: Container(
                              //     child: Column(
                              //       children: [
                              //         Text("Totalorders".tr,
                              //             style: TextStyle(
                              //               color: Colors.black54,
                              //               fontWeight: FontWeight.w700,
                              //               fontSize: 17,
                              //             )),
                              //         Container(
                              //           height: 8,
                              //         ),
                              //         Text("$listAllNum",
                              //             style: TextStyle(
                              //               color: Colors.black54,
                              //               fontWeight: FontWeight.w700,
                              //               fontSize: 17,
                              //             ))
                              //       ],
                              //     ),
                              //   ),
                              // ),
                              Container(
                                padding: EdgeInsets.only(left: 5,right: 5,top: 15,bottom: 10),
                                child: Container(
                                  child: Column(
                                    children: [
                                      Text(
                                        "Todaysincome".tr,
                                        style: TextStyle(color: Colors.black54),
                                      ),
                                      Container(
                                        height: 8,
                                      ),
                                      Text("$listDayCount", style: TextStyle(color: Colors.black54))
                                    ],
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                        // Container(
                        //   margin: EdgeInsets.only(top: 15),
                        //   width: MediaQuery.of(context).size.width - 50,
                        //   padding: EdgeInsets.all(5),
                        //   decoration: BoxDecoration(
                        //     color: Color(0xffffffff),
                        //     borderRadius: BorderRadius.circular(10.0),
                        //     boxShadow: [
                        //       BoxShadow(
                        //           color: Colors.black12,
                        //           offset: Offset(0.0, 0.0), //阴影x轴偏移量
                        //           blurRadius: 5, //阴影模糊程度
                        //           spreadRadius: 1 //阴影扩散程度
                        //       )],
                        //   ),
                        //   child: Row(
                        //     mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        //     children: [
                        //       Container(
                        //         padding: EdgeInsets.only(left: 5,right: 5,top: 15,bottom: 10),
                        //         child: Container(
                        //           // padding: EdgeInsets.only(right: 15),
                        //           // decoration: BoxDecoration(
                        //           //     border: Border(right: BorderSide(color: Colors.white,width: 0.5,style: BorderStyle.solid))
                        //           // ),
                        //           child: Column(
                        //             children: [
                        //               Text("OrderToday".tr, style: TextStyle(color: Colors.black54)),
                        //               Container(
                        //                 height: 8,
                        //               ),
                        //               Text("$listDayNum", style: TextStyle(color: Colors.black54))
                        //             ],
                        //           ),
                        //         ),
                        //       ),
                        //       Container(
                        //         padding: EdgeInsets.only(left: 5,right: 5,top: 15,bottom: 10),
                        //         child: Container(
                        //           child: Column(
                        //             children: [
                        //               Text("Totalorders".tr,
                        //                   style: TextStyle(
                        //                     color: Colors.black54,
                        //                     fontWeight: FontWeight.w700,
                        //                     fontSize: 17,
                        //                   )),
                        //               Container(
                        //                 height: 8,
                        //               ),
                        //               Text("$listAllNum",
                        //                   style: TextStyle(
                        //                     color: Colors.black54,
                        //                     fontWeight: FontWeight.w700,
                        //                     fontSize: 17,
                        //                   ))
                        //             ],
                        //           ),
                        //         ),
                        //       ),
                        //       Container(
                        //         padding: EdgeInsets.only(left: 5,right: 5,top: 15,bottom: 10),
                        //         child: Container(
                        //           child: Column(
                        //             children: [
                        //               Text(
                        //                 "Todaysincome".tr,
                        //                 style: TextStyle(color: Colors.black54),
                        //               ),
                        //               Container(
                        //                 height: 8,
                        //               ),
                        //               Text("$listDayCount", style: TextStyle(color: Colors.black54))
                        //             ],
                        //           ),
                        //         ),
                        //       ),
                        //     ],
                        //   ),
                        // )
                      ],
                    ),),


                  ],
                ),
                //金刚区
                Expanded(
                  child: Container(

                    margin: EdgeInsets.only(top: 60,left: 10,right: 10),
                    padding: EdgeInsets.all(15),
                    child: GridView.builder(
                      //GridView内边距
                      padding: EdgeInsets.all(5.0),
                      // physics: NeverScrollableScrollPhysics(),
                      shrinkWrap: true,
                      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                          crossAxisCount: 2, crossAxisSpacing: 10.0, mainAxisSpacing: 10.0, childAspectRatio: 1.5),
                      itemCount: permissions == 0
                          ? XiaoShouHomeList.length
                          : permissions == 1
                          ? CangGuanHomeList.length
                          : DianZhangHomeList.length,
                      itemBuilder: (BuildContext context, int index) {
                        return GestureDetector(
                          child: Container(

                            padding: EdgeInsets.all(10),
                            decoration: BoxDecoration(
                                color: Color(0xffffffff),
                              borderRadius: BorderRadius.circular(8),
                              // boxShadow: [
                              //   BoxShadow(
                              //       color: Colors.black12,
                              //     offset: Offset(0.0, 0.0), //阴影x轴偏移量
                              //     blurRadius:4, //阴影模糊程度
                              //     spreadRadius: 0.5 //阴影扩散程度
                              // )],
                            ),
                            child: Row(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                //功能名和icon
                                Container(
                                  child: Column(
                                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                    children: [
                                      Container(
                                        child: Image.asset(
                                            "Image/${permissions == 0 ? XiaoShouHomeList[index]['ImgUrl'] : permissions == 1 ? CangGuanHomeList[index]['ImgUrl'] : DianZhangHomeList[index]['ImgUrl']}blue.png"),
                                        width: 40,
                                        height: 40,
                                      ),
                                      Text(
                                        "${permissions == 0 ? XiaoShouHomeList[index]['Name'] : permissions == 1 ? CangGuanHomeList[index]['Name'] : DianZhangHomeList[index]['Name']}",
                                        style: TextStyle(color: Color(0xff000000)),
                                      )
                                    ],
                                  ),
                                ),
                                //点击进入按钮
                                Container(
                                  child: Text(
                                    "enter".tr,
                                    style: TextStyle(color: Colors.white, fontSize: 13),
                                  ),
                                  width: 40,
                                  height: 20,
                                  decoration: BoxDecoration(
                                    borderRadius: BorderRadius.all(Radius.circular(5)),
                                    color: Color(0xff4890e2),
                                  ),
                                  alignment: Alignment.center,
                                )
                              ],
                            ),
                          ),
                          onTap: (){
                            //当前销售点击
                            if(permissions==0){
                              if(XiaoShouHomeList[index]['id']==0){
                                //进入设备连接
                                Get.to(DeviceConnect());
                              }
                              if(XiaoShouHomeList[index]['id']==7){
                                //进入物资录入
                                Get.to(GoodsLuRu());
                              }
                              if(XiaoShouHomeList[index]['id']==8){
                                //进入会员登记
                                Get.to(VipAdd());
                              }
                              if(XiaoShouHomeList[index]['id']==9){
                                //进入销售记录
                                Get.to(SalNotes());
                              }
                            }
                            //仓管
                            if(permissions==1){
                              if(CangGuanHomeList[index]['id']==0){
                                //进入设备连接
                                Get.to(DeviceConnect());
                              }
                              if(CangGuanHomeList[index]['id']==1){
                                //进入物资入库
                                Get.to(PrfOrderList());
                              }
                              if(CangGuanHomeList[index]['id']==2){
                                //进入物资出库
                                Get.to(OutOrderList());
                              }
                              if(CangGuanHomeList[index]['id']==3){
                                //进入物资盘点
                                Get.to(GoodsInventoryList());
                              }
                              if(CangGuanHomeList[index]['id']==4){
                                //进入库存查询
                                Get.to(GoodsSearch());
                              }
                              if(CangGuanHomeList[index]['id']==5){
                                //进入库存调拨
                                Get.to(GoodsTransferList());
                              }
                            }
                            //店长
                            if(permissions==2){
                              if(DianZhangHomeList[index]['id']==0){
                                //进入设备连接
                                Get.to(DeviceConnect());
                              }
                              if(DianZhangHomeList[index]['id']==1){
                                //进入物资入库
                                Get.to(PrfOrderList());
                              }
                              if(DianZhangHomeList[index]['id']==2){
                                //进入物资出库
                                Get.to(OutOrderList());
                              }
                              if(DianZhangHomeList[index]['id']==3){
                                //进入物资盘点
                                Get.to(GoodsInventoryList());
                              }
                              if(DianZhangHomeList[index]['id']==4){
                                //进入库存查询
                                Get.to(GoodsSearch());
                              }
                              if(DianZhangHomeList[index]['id']==5){
                                //进入库存调拨
                                Get.to(GoodsTransferList());
                              }
                              if(DianZhangHomeList[index]['id']==7){
                                //进入物资录入
                                Get.to(GoodsLuRu());
                              }
                              if(DianZhangHomeList[index]['id']==8){
                                //进入会员登记
                                Get.to(VipAdd());
                              }
                              if(DianZhangHomeList[index]['id']==9){
                                //进入销售记录
                                Get.to(SalNotes());
                              }
                            }
                          },
                        );
                      },
                    ),
                  ),
                ),


//                金刚区
                // Expanded(
                //   child: Container(
                //     margin: EdgeInsets.only(top: 10,left: 10,right: 10),
                //     padding: EdgeInsets.all(15),
                //     child: GridView.builder(
                //       // physics: NeverScrollableScrollPhysics(),
                //       shrinkWrap: true,
                //       gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                //           crossAxisCount: 2, crossAxisSpacing: 20.0, mainAxisSpacing: 15.0, childAspectRatio: 1.5),
                //       itemCount: permissions == 0
                //           ? XiaoShouHomeList.length
                //           : permissions == 1
                //           ? CangGuanHomeList.length
                //           : DianZhangHomeList.length,
                //       itemBuilder: (BuildContext context, int index) {
                //         return GestureDetector(
                //             child: Container(
                //               padding: EdgeInsets.all(10),
                //                 decoration: BoxDecoration(
                //                   // color: Color(0xffEEF4F4),
                //                   borderRadius: BorderRadius.circular(8),
                //                     gradient: LinearGradient(
                //                         begin: Alignment.topCenter,//渐变开始于上面的中间开始
                //                         end: Alignment.bottomCenter,//渐变结束于下面的中间
                //                         colors: [Color(0xff95c1fe), Color(0xff91c4fd),Color(0xff8dcbfe),Color(0xff87d0fb),Color(0xff85d3ff)]),
                //                 ),
                //               child: Column(
                //                   mainAxisAlignment: MainAxisAlignment.spaceBetween,
                //                   children: [
                //                     Container(
                //                       child: Image.asset(
                //                           "Image/${permissions == 0 ? XiaoShouHomeList[index]['ImgUrl'] : permissions == 1 ? CangGuanHomeList[index]['ImgUrl'] : DianZhangHomeList[index]['ImgUrl']}.png"),
                //                       width: 40,
                //                       height: 40,
                //                     ),
                //                     Text(
                //                       "${permissions == 0 ? XiaoShouHomeList[index]['Name'] : permissions == 1 ? CangGuanHomeList[index]['Name'] : DianZhangHomeList[index]['Name']}",
                //                       style: TextStyle(color: Color(0xffffffff)),
                //                     )
                //                   ],
                //                 ),
                //             ),
                //             // child: Container(
                //             //   padding: EdgeInsets.all(10),
                //             //   decoration: BoxDecoration(
                //             //     // color: Color(0xffEEF4F4),
                //             //     borderRadius: BorderRadius.circular(8),
                //             //   ),
                //             //   child: Row(
                //             //     crossAxisAlignment: CrossAxisAlignment.start,
                //             //     mainAxisAlignment: MainAxisAlignment.spaceBetween,
                //             //     children: [
                //             //       //功能名和icon
                //             //       Container(
                //             //         child: Column(
                //             //           mainAxisAlignment: MainAxisAlignment.spaceBetween,
                //             //           children: [
                //             //             Container(
                //             //               child: Image.asset(
                //             //                   "Image/${permissions == 0 ? XiaoShouHomeList[index]['ImgUrl'] : permissions == 1 ? CangGuanHomeList[index]['ImgUrl'] : DianZhangHomeList[index]['ImgUrl']}.png"),
                //             //               width: 40,
                //             //               height: 40,
                //             //             ),
                //             //             Text(
                //             //               "${permissions == 0 ? XiaoShouHomeList[index]['Name'] : permissions == 1 ? CangGuanHomeList[index]['Name'] : DianZhangHomeList[index]['Name']}",
                //             //               style: TextStyle(color: Color(0xff372D9F)),
                //             //             )
                //             //           ],
                //             //         ),
                //             //       ),
                //             //       //点击进入按钮
                //             //       // Container(
                //             //       //   child: Text(
                //             //       //     "enter".tr,
                //             //       //     style: TextStyle(color: Colors.white, fontSize: 13),
                //             //       //   ),
                //             //       //   width: 40,
                //             //       //   height: 20,
                //             //       //   decoration: BoxDecoration(
                //             //       //     borderRadius: BorderRadius.all(Radius.circular(5)),
                //             //       //     color: Color(0xff372D9F),
                //             //       //   ),
                //             //       //   alignment: Alignment.center,
                //             //       // )
                //             //     ],
                //             //   ),
                //             // ),
                //
                //           onTap: (){
                //             //当前销售点击
                //             if(permissions==0){
                //               if(XiaoShouHomeList[index]['id']==0){
                //                 //进入设备连接
                //                 Get.to(DeviceConnect());
                //               }
                //               if(XiaoShouHomeList[index]['id']==7){
                //                 //进入物资录入
                //                 Get.to(GoodsLuRu());
                //               }
                //               if(XiaoShouHomeList[index]['id']==8){
                //                 //进入会员登记
                //                 Get.to(VipAdd());
                //               }
                //               if(XiaoShouHomeList[index]['id']==9){
                //                 //进入销售记录
                //                 Get.to(SalNotes());
                //               }
                //             }
                //             //仓管
                //             if(permissions==1){
                //               if(CangGuanHomeList[index]['id']==0){
                //                 //进入设备连接
                //                 Get.to(DeviceConnect());
                //               }
                //               if(CangGuanHomeList[index]['id']==1){
                //                 //进入物资入库
                //                 Get.to(PrfOrderList());
                //               }
                //               if(CangGuanHomeList[index]['id']==2){
                //                 //进入物资出库
                //                 Get.to(OutOrderList());
                //               }
                //               if(CangGuanHomeList[index]['id']==3){
                //                 //进入物资盘点
                //                 Get.to(GoodsInventoryList());
                //               }
                //               if(CangGuanHomeList[index]['id']==4){
                //                 //进入库存查询
                //                 Get.to(GoodsSearch());
                //               }
                //               if(CangGuanHomeList[index]['id']==5){
                //                 //进入库存调拨
                //                 Get.to(GoodsTransferList());
                //               }
                //             }
                //             //店长
                //             if(permissions==2){
                //               if(DianZhangHomeList[index]['id']==0){
                //                 //进入设备连接
                //                 Get.to(DeviceConnect());
                //               }
                //               if(DianZhangHomeList[index]['id']==1){
                //                 //进入物资入库
                //                 Get.to(PrfOrderList());
                //               }
                //               if(DianZhangHomeList[index]['id']==2){
                //                 //进入物资出库
                //                 Get.to(OutOrderList());
                //               }
                //               if(DianZhangHomeList[index]['id']==3){
                //                 //进入物资盘点
                //                 Get.to(GoodsInventoryList());
                //               }
                //               if(DianZhangHomeList[index]['id']==4){
                //                 //进入库存查询
                //                 Get.to(GoodsSearch());
                //               }
                //               if(DianZhangHomeList[index]['id']==5){
                //                 //进入库存调拨
                //                 Get.to(GoodsTransferList());
                //               }
                //               if(DianZhangHomeList[index]['id']==7){
                //                 //进入物资录入
                //                 Get.to(GoodsLuRu());
                //               }
                //               if(DianZhangHomeList[index]['id']==8){
                //                 //进入会员登记
                //                 Get.to(VipAdd());
                //               }
                //               if(DianZhangHomeList[index]['id']==9){
                //                 //进入销售记录
                //                 Get.to(SalNotes());
                //               }
                //             }
                //           },
                //         );
                //       },
                //     ),
                //   ),
                // ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  //获取用户信息
  Future<void> GetUserMessage() async {
    KSProgressDialog().LoadingToast("Gettheinformation".tr, context);
    var ResultData = await new UserMessage().GetUser();
    KSProgressDialog().CloseLoading();
   if(ResultData['code'] == 200){
     roleName = ResultData['user']['nickName'];
     //个人信息保存本地
     await getStorage.write("User", json.encode(ResultData));
     List permissionList = ResultData['permissions'];

     if (permissionList.contains("system:stkio:query") && !permissionList.contains("system:salquot:query")) {
       print("仓管权限");
       permissions = 1;
       await GetIventoryList();
     }
     if (permissionList.contains("system:salquot:query") && !permissionList.contains("system:stkio:query")) {
       print("销售权限");
       permissions = 0;
       //获取订单和收入
       await GetSalOrder();
     }
     if (permissionList.contains("system:salquot:query") && permissionList.contains("system:stkio:query")) {
       print("店长权限");
       permissions = 2;
       //获取订单和收入
       await GetSalOrder();
       await GetIventoryList();
     }
     await getStorage.write("permissions", permissions);

   }else {
     new GetxTools().ErrorToast("Informationacquisitionfailed".tr);
   }
    setState(() {});
  }

  //销售和店长获取订单数和收入
  GetSalOrder() async {
    //取出本地个人信息
    GetStorage getStorage = new GetStorage();
    var Userid = json.decode(getStorage.read("User"))['user']['userId'];
    var data ;
    if(permissions==2){
      data = {
        "appDate":DateTime.now().toString().substring(0,10)
      };
    }else{
      data = {
        "operator":Userid,
        "appDate":DateTime.now().toString().substring(0,10)
      };
    }
    var ResultData = await new SaleManage().SalOrderList(data);

    if(ResultData['code'] == 200){
      var data = ResultData['data'];
      listDayNum = data['listDayNum'];
      listDayCount = data['listDayCount'];
      listAllNum = data['listAllNum'];
      //保存数据到本地
     await getStorage.write("HomeSalData", json.encode(data));
    }else {
      new GetxTools().ErrorToast("Informationacquisitionfailed".tr);
    }
    setState(() {
    });
  }
  //仓管和店长获取出入库数据
  GetIventoryList() async {
    //取出本地个人信息
    GetStorage getStorage = new GetStorage();
    var Userid = json.decode(getStorage.read("User"))['user']['userId'];
    var data ;
    if(permissions==2){
      data = {
        "appDate":DateTime.now().toString().substring(0,10)
      };
    }else{
      data = {
        "operator":Userid,
        "appDate":DateTime.now().toString().substring(0,10)
      };
    }
    var ResultData = await new KuCunManager().InventoryDataList(data);
    if(ResultData['code'] == 200){
      var data = ResultData['data'];
      listDayOut = data['listDayOut'];
      listDay = data['listDay'];
      listAll = data['listAll'];
      //保存数据到本地
      await getStorage.write("HomeCangGuanData", json.encode(data));
    }else {
      new GetxTools().ErrorToast("Informationacquisitionfailed".tr);
    }
    setState(() {
    });
  }
}
